/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dal;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 *
 * @author MinhDuc
 */
public class ConnectDatabase {

    private static Connection connect;

    public ConnectDatabase() {
    }

    public static Connection getConnection() {
        try {
            Properties property = new Properties();
            property.load(new FileInputStream("DBConfig.properties"));
            String driver = property.getProperty("driver");
            String url = property.getProperty("url");
            String userName = property.getProperty("username");
            String password = property.getProperty("password");

            Class.forName(driver);
            connect = DriverManager.getConnection(url, userName, password);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return connect;
    }

    public static boolean CloseConnection() {
        if (connect != null) {
            try {
                connect.close();
                return true;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return false;
    }

    public static boolean testConnection() {
        if (connect != null) {
            return true;
        } else {
            return false;
        }
    }
}
